1. Field of the Invention
The present invention generally relates to an apparatus and a method for sorting data, in particular, to an apparatus and a method for sorting a raw data with horizontal division.
2. Description of Related Art
Along with the advancement of semiconductor and photo-electricity technologies, digital cameras, digital monitors, and digital video cameras have been broadly applied in our daily lives. In a photographic apparatus (for example, a digital camera, a digital monitor, or a digital video camera), a photosensitive device is used for converting an optical signal into an electrical signal. The photosensitive device is usually a charge coupled device (CCD) or a complementary metal-oxide semiconductor (CMOS) image sensor, wherein a CCD offers better image quality than a CMOS image sensor.
FIG. 1 illustrates a format of an image data produced by a conventional CCD. As shown in FIG. 1, the image data 10 produced by the CCD has five vertical fields Field 1˜Field 5. Assuming that the image data 10 contains 45×60 pixels, each of the vertical fields Field 1˜Field 5 has 9 rows of data, and the each row of data has 60 pixels. After the CCD renders the image, the vertical field Field i has the data of the (5*k+i)th row, wherein k is an integer of 0 to (45/5−1)=8, and i is an integer of 1 to 5.
However, foregoing image data cannot be displayed in foregoing format, and accordingly, the image data has to be sorted before it can be displayed, wherein the sorting process can be implemented with software or hardware.
FIG. 2 illustrates the sorting mechanism of an image data 20 produced by a conventional CCD. The image data 20 stored in a frame memory has five vertical fields Field 1˜Field 5. During the first sorting run, the data block 201 of the first Hstripe columns is read, and a row sorting is then performed to the data block 201 according to the number of the vertical fields (there are five vertical fields in the present embodiment), and the originally-read data block 201 is then overwritten by the sorted data block 211. During the next run, data block 202 is read, and a row sorting is performed thereto, and then the originally-read data block 202 is overwritten by the sorted data block. This process goes on until the sorting of the entire image data 20 is completed, so that the sorted image data can be displayed in a display apparatus.
An example will be described herein. Here it is assumed that the image data 20 contains 45×60 pixels, the value of Hstripe is 20, each of the vertical fields Field 1˜Field 5 has 9 rows of data, and each row of data has 60 pixels. After the CCD renders the image, the vertical field Field i has the data of the (5*k+i)th row, wherein k is an integer of 0 to 8, and i is an integer of 1 to 5. According to the conventional sorting method, the data block of the first 20 columns is first read. Then, a row sorting is performed to the data block of the first 20 columns according to the number of the vertical fields, so that the vertical field Field 1 has the data of rows 1˜9, the vertical field Field 2 has the data of rows 10˜18, the vertical field Field 3 has the data of rows 19˜27, the vertical field Field 4 has the data of rows 28˜36, and the vertical field Field 5 has the data of rows 37˜45, wherein each row of data contains pixels 1˜20. After that, the originally-read data block of the first 20 columns is overwritten by the sorted data block of the first 20 columns.
Thereafter, the data block of columns 21˜40 is read, and a row sorting is performed to the data block of columns 21˜40 according to the number of the vertical fields, so that the vertical field Field 1 has the data of rows 1˜9, the vertical field Field 2 has the data of rows 10˜18, the vertical field Field 3 has the data of rows 19˜27, the vertical field Field 4 has the data of rows 28˜36, and the vertical field Field 5 has the data of rows 37˜45, wherein each row of data contains pixels 21˜40. After that, the originally-read data block of columns 21˜40 is overwritten by the sorted data block of columns 21˜40.
Finally, the data block of columns 41˜60 is read, and a row sorting is performed to the data block of columns 41˜60 according to the number of the vertical fields, so that the vertical field Field 1 has the data of rows 1˜9, the vertical field Field 2 has the data of rows 10˜18, the vertical field Field 3 has the data of rows 19˜27, the vertical field Field 4 has the data of rows 28˜36, and the vertical field Field 5 has the data of rows 37˜45, wherein each row of data contains pixels 41˜60. After that, the originally-read data block of columns 41˜60 is overwritten by the sorted data block of columns 41˜60. By now, the sorting of the entire image data is completed.
However, in order to obtain a better image quality, another format of image data produced by CCD is provided. FIG. 3 illustrates the other format of image data produced by a conventional CCD. Referring to FIG. 3, the image data 30 includes 5 vertical fields, wherein the first vertical field further includes 3 horizontal fields Field 1-1, Field 1-2, and Field 1-3, the second vertical field further includes 3 horizontal fields Field 2-1, Field 2-2, and Field 2-3, and so on. Assuming that the image data contains 45×60 pixels, the ith vertical field has the data of the (5*k+i)th row, wherein k is an integer of 0 to 8, and i is an integer of 1 to 5; and the data of the nth horizontal field Field i-n in the ith vertical field has the (n+3*m)th pixel in the (5*k+i)th row, wherein n is an integer of 1 to 3, and m is an integer of 0 to (60/3−1)=19.
The image data 30 cannot be sorted into a format acceptable a display apparatus in the same way as illustrated in FIG. 2. However, this purpose can be accomplished through software and the calculations of a central processing unit (CPU).
FIG. 4 illustrates a method for sorting the image data 30 with horizontal division through CPU calculations and the timing thereof. In this method, horizontal fields Field i-1˜Field i-3 of the image data 30 are read every time when a vertical synchronous signal VD drops from a high level to a low level, wherein i is an integer of 1 to 5. After the entire image data 30 has been read, the CPU sorts the image data 30 into a format which can be displayed in a display apparatus according to a sorting algorithm.
However, in the method described above, it takes 5 cycles of the vertical synchronous signal VD to read the image data 30 and a long execution time Tcpu for the CPU to sort the entire image data 30 into aforementioned format. Besides, a large memory space is required for storing the entire image data, and such a large memory space increases the area of the hardware. Accordingly, long calculation time and large memory space are required in order to sort the image data 30 with horizontal division as illustrated in FIG. 3 into a format acceptable to a display apparatus.
In order to resolve foregoing problems, the present invention provides an apparatus and a method for sorting an image data with horizontal division into a format acceptable to a display apparatus by revising existing hardware structure, wherein both the calculation time and memory space required for sorting the image data are reduced.